package com.yiwei.zxp.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;

import com.yiwei.zxp.R;
import com.yiwei.zxp.activity.GoodsAddActivity;
import com.yiwei.zxp.api.model.ShopAuthInfoModel;
import com.yiwei.zxp.util.Util;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * Created by xsooy-pc on 18-8-2.
 */

public class ShopIdentityOneFragment extends BaseFragment {
    @BindView(R.id.txt_shop_name)
    TextView txtShopName;
    @BindView(R.id.edit_shop_name)
    EditText editShopName;
    @BindView(R.id.txt_address)
    TextView txtAddress;
    @BindView(R.id.edit_address)
    TextView editAddress;
    @BindView(R.id.txt_phone)
    TextView txtPhone;
    @BindView(R.id.edit_phone)
    EditText editPhone;
    @BindView(R.id.txt_type)
    TextView txtType;
    @BindView(R.id.edit_type)
    TextView editType;
    @BindView(R.id.txt_identity)
    TextView txtIdentity;
    @BindView(R.id.edit_identity)
    TextView editIdentity;
    @BindView(R.id.btn_submit)
    TextView btnSubmit;
    Unbinder unbinder;
    private ShopAuthInfoModel.DatasBean data;

    public void setData(ShopAuthInfoModel.DatasBean data) {
        this.data = data;
    }

    @Override
    protected int setLayoutId() {
        return R.layout.fragment_shop_identity_one;
    }

    @Override
    protected void initView() {
        if (data != null) {
            editShopName.setText(data.shop_name);
            editAddress.setText(data.address);
            editPhone.setText(data.phone);
            if (data.cate_lists != null && data.cate_lists.size() >= 0) {
                StringBuilder builder = new StringBuilder();
                for (int i = 0; i < data.cate_lists.size(); i++) {
                    builder.append(data.cate_lists.get(i).catname);
                    builder.append("、");
                }
                editType.setText(builder.substring(0, builder.length() - 1));

            }
            switch (data.status) {
                case "-1":
                    editIdentity.setText("审核失败" + data.mesg);
                    break;
                case "0":
                    editIdentity.setText("待审");
                    break;
                case "1":
                    editIdentity.setText("已通过");
                    break;
            }

        }
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        unbinder = ButterKnife.bind(this, rootView);
        return rootView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @OnClick(R.id.btn_submit)
    public void onViewClicked() {
        Util.startActivity(getContext(), GoodsAddActivity.class);
        getActivity().finish();
    }
}
